package com.itheima.servlet03;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

public class servletDemo003 extends HttpServlet {

    private ServletConfig config;

    @Override
    public void init(ServletConfig config) throws ServletException {
        this.config=config;
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String s = config.getInitParameter("ConfigDemo");
        System.out.println(s);
        String s1 = config.getServletName();
        System.out.println(s1);

        Enumeration<String> ss = config.getInitParameterNames();
        while (ss.hasMoreElements()){
            String ss2 = ss.nextElement();
            String initParameter = config.getInitParameter(ss2);
            System.out.println(ss2+","+initParameter);
        }

        ServletContext servletContext = config.getServletContext();
//        System.out.println(servletContext);
        System.out.println("servletContext = " + servletContext);
        Object obj = servletContext.getAttribute("encoding");
        System.out.println(obj);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }

}

